
# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane

fastlane_require 'dotenv'

default_platform(:ios)

before_all do
      Dotenv.overload '.env.secret'
      Dotenv.overload '.env.default'
end

lane :objectlint do
    oclint(
      compile_commands: "compile_commands.json",    # The JSON compilation database, use xctool reporter "json-compilation-database"
      select_regex: /ViewController.m/,     # Select all files matching this regex
      exclude_regex: /Test.m/,    # Exclude all files matching this regex
      report_type: "html",         # The type of the report (default: html)
      report_path: "fastlane/oclint/objectlint.html",
      max_priority_1: 8,         # The max allowed number of priority 1 violations
      max_priority_2: 9,        # The max allowed number of priority 2 violations
      max_priority_3: 10,       # The max allowed number of priority 3 violations
      thresholds: [     # Override the default behavior of rules
        "LONG_LINE=200",
        "LONG_METHOD=200"
      ],
      enable_rules: [   # List of rules to pick explicitly
        "DoubleNegative",
        "SwitchStatementsDon'TNeedDefaultWhenFullyCovered"
      ],
      disable_rules: ["GotoStatement"],     # List of rules to disable
      list_enabled_rules: true,   # List enabled rules
      enable_clang_static_analyzer: true,   # Enable Clang Static Analyzer, and integrate results into OCLint report
      enable_global_analysis: true,         # Compile every source, and analyze across global contexts (depends on number of source files, could results in high memory load)
      allow_duplicated_violations: true,    # Allow duplicated violations in the OCLint report
      extra_arg: "-Wno-everything"# Additional argument to append to the compiler command line
)
end

lane :swiftylint do
     swiftlint(
         reporter: "html",
         output_file: "fastlane/swiftlint.html",
      ignore_exit_status: true
              )
end

lane :test do
  
     scan(
         scheme: ENV['XCODE_SCHEME'],
         output_directory: "fastlane/tests",
         clean: true
         )
end


lane :build do

     # incerment the build number
     increment_build_number(
         build_number: ENV['CI_JOBENV_ID'],
         xcodeproj: ENV['XCODE_PROJECT']
         )

     # BUILD
     gym(
         scheme: ENV['XCODE_SCHEME'],
         configuration: ENV['DEVELOP_CONFIGURATION'],
         export_method: ENV['DEVELOP_EXPORT_METHOD'],
         #export_xargs: ENV['DEVELOP_XARGS'],
         silent: true,
         clean: true,
      codesigning_identity: "Apple Distribution: yangui xi (9S6T5CVY8R)",
      export_options: {
          provisioningProfiles: {
            "com.xyg.fastlane" => "home_distrib"
        }
      }
         )

  end
  
lane :pgy_upload do
    # incerment the build number
  increment_build_number(
         build_number: ENV['CI_JOBENV_ID'],
         xcodeproj: ENV['XCODE_PROJECT']
         )
  build_app(
      #workspace: "MyApp.xcworkspace",
      configuration: "Debug",
      scheme: ENV['XCODE_SCHEME'],
      silent: true,
      clean: true,
      output_directory: "fastlane/pgy", # Destination directory. Defaults to current directory.
      output_name: "pgy_debug.ipa",       # specify the name of the .ipa file to generate (including file extension)
      sdk: "iOS 15.2"        # use SDK as the name or path of the base SDK when building the project.
)
  pgyer(api_key: "10deff014b5276d83f1c368a662071d1", user_key: "b0bc3076c06dc48532eb58bb7b236b2d")
end


lane :tf_upload do
  # incerment the build number
  increment_build_number(
         build_number: ENV['CI_JOBENV_ID'],
         xcodeproj: ENV['XCODE_PROJECT']
         )
  gym(
          clean: true,
          output_directory: './fastlane/tf',
          output_name:"testflight.ipa",
          scheme: ENV['XCODE_SCHEME'],
          configuration: ENV['DEVELOP_CONFIGURATION'],###########
          include_bitcode: true,
          include_symbols: true,
          codesigning_identity:"Apple Distribution: yangui xi (9S6T5CVY8R)",
          export_options: {
            method: 'app-store',
            provisioningProfiles: {
               "com.xyg.fastlane" => "home_distrib"
            },
          }
    )
    notification(app_icon:"./fastlane/icon.png",title:"LoanManager",subtitle: "打包成功,已导出安装包>>>>>>>>", message: "准备发布中....")
    api_key = app_store_connect_api_key(
        key_id: "UU657JJ8N5",
        issuer_id: "ffa427b7-d74d-4a21-8993-8f0477176e7d",
        key_filepath: "./fastlane/AuthKey_UU657JJ8N5.p8",
        duration: 1200, # optional (maximum 1200)
        in_house: false # optional but may be required if using match/sigh
      )
      
    upload_to_testflight(
      api_key: api_key,
      skip_waiting_for_build_processing: true,
      # username: "1xxxx@163.com",
      # app_identifier: "com.sxx.xxx",
      ipa: "./fastlane/tf/testflight.ipa",
      skip_submission:true
     )
end



platform :ios do
  desc "Description of what the lane does"
  lane :custom_lane do
    # add actions here: https://docs.fastlane.tools/actions
  end
end
